package com.training.schedule_management_system_admin.config;

import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.ShiroException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GloablExceptionHandler {

    @ResponseBody
    @ExceptionHandler(ShiroException.class)
    public JSONObject handleShiroException(){
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("message","您没有权限访问");
        return jsonObject;
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public JSONObject handleException(Exception e){
        String msg=e.getMessage();
        if(msg==null||msg.equals("")){
            msg="服务器出错";
        }
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("message",msg);
        return jsonObject;
    }
}
